home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
AVOGADRO
/
SCIDISCS
/
DISC2
/
GREENING.SPK
/
ReadBigNum
< prev
next >
Wrap
Text File
|
1993-11-27
|
5KB
|
108 lines
BIGNUMBERS
John Greening
(These programs may be freely copied provided that this file is
attached and they are not sold for profit. They are used entirely at
your own risk.)
All the programs in this directory and its sub-directories deal with
big numbers. BASIC V can handle integers up to 2147483647 (ie.
2^31-1), but if you want to use larger integers you need special
programs. BASIC V will normally state real numbers to 9 digits plus
the power of ten required. By using extended precision with the
FPEmulator 19 digits can be obtained. If higher precision is required
special programs are again needed.
The programs in this directory handle numbers with up to 255 digits.
This limit is set by 255 characters being the longest string that
BASIC V can use. Although most of the work done by the programs is
carried out using arrays some string properties are employed.
All numbers must be entered into these programs as strings of digits
(with a decimal point in the case of reals). There must be no power
signs (ie. ^) or scientific notation (eg. E10). All numbers must be
positive and the results of any calculations must be positive. Thus
if you subtract it must always be a smaller number from a larger
number.
BigIntegr1
The program BigIntegr1 will add, subtract, multiply or divide positive
integers of up to 255 digits. You will be prompted for the maximum
number of digits you wish to use. You will then be prompted for the
first and then the second number. If the product of the two integers
is likely to have more than the maximum number of digits you have set,
you will be warned. You will be asked if you wish to interchange the
numbers. This may be necessary in the cases of subtraction (see
above) or division. If you divide a smaller number by a larger one you
will get the trivial result 0 with a remainder equal to the smaller
number. You will then be prompted for the action you require,
ie.addition, subtraction, multiplication or division. The result will
appear and you will be prompted for the number you wish to use with
this result. The other prompts will be repeated. Although all this
prompting may be helpful to start with, you may find it tedious
eventually. In this case turn to the next program.
BigIntegr2
This does the same things as BigIntegr1 but with fewer prompts. You
will be prompted to enter two numbers, but if you wish to swap them
you must press # (on the right hand keypad or elsewhere). You then
press +, -, * or / (again on the right hand keypad or elsewhere)
depending on the action you require. When the result appears you will
be prompted for the number to be used with this result.
BigSqRoots
This program calculates the square roots of positive integers or real
numbers having up to 255 digits. (In the case of reals the decimal
point counts as a digit). The result can be given in up to 127 digits.
For an integer you can always use this number of digits if you wish,
but for reals there is no point in getting a result to more than half
the number of digits of the original number as the accuracy with
which the real number is known does not justify it. Do not rely on
the last digit.
BigReals
USE THIS PROGRAM WITH GREAT CARE!
This program carries out the same functions as BigIntegr1 but it
accepts real numbers as well as integers and gives the option of taking
square roots as well as the normal arithmetical functions. The
results of divisions are given as real numbers to the number of digits
requested and remainders are not stated as they have little
meaning in these circumstances.
I offer it with some trepidation as it is only too easy for you to get
a false idea of accuracy. This has been discussed to some extent
under BigSqRoots, but it also applies to the normal arithmetic
operations. Thus if you multiply two 50 digit integers together you
will get a 99 or 100 digit product in which every digit is
justified; but if the numbers are reals instead of integers only
the first 50 digits are really worth having because the original
numbers are not known to more than 50 places. Similar problems can
arise with addition, subtraction and division. So it will be up to you
to decide just how many of the digits offered to you in the results of calculations you wish to retain.
Directory Mersenne
This directory has its own ReadMersen file.
I should like to record the help I have received from Chapter 4 of
"Microcomputers and Mathematics" by Bruce, Giblin and Rippon, CUP in
the preparation of these programs.
If you want some interesting big numbers to work on see "The Penguin
Dictionary of Curious and Interesting Numbers" by David Wells.
John Greening
15, Pentland Crescent,
Edinburgh, EH10 6NS